using RuoVea.Service;
using Microsoft.AspNetCore.Mvc;

namespace RuoVea.Api.Controllers
{
    /// <summary>
    /// 系统菜单服务
    /// </summary>
    public class SysMenuController :    ApiBaseController 
    {
        private readonly ISysMenuService _sysMenuService;  // 菜单表仓储  
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sysMenuService"></param>
        public SysMenuController(ISysMenuService sysMenuService)
        {
            _sysMenuService = sysMenuService; 
        }

        /// <summary>
        /// 系统菜单列表（树表）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<dynamic> GetMenuList([FromQuery] MenuInput input)
        {
            return await _sysMenuService.GetMenuList(input);
        }

        /// <summary>
        /// 增加系统菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task AddMenu(AddMenuInput input)
        {
            await _sysMenuService.AddMenu(input);
        }

        /// <summary>
        /// 删除系统菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task DeleteMenu(DeleteMenuInput input)
        {
            await _sysMenuService.DeleteMenu(input);
        }

        /// <summary>
        /// 更新系统菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("edit"),]
        public async Task UpdateMenu(UpdateMenuInput input)
        {
            await _sysMenuService.UpdateMenu(input);
        }

        /// <summary>
        /// 获取系统菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("detail")]
        public async Task<dynamic> GetMenu(QueryMenuInput input)
        {
            return await _sysMenuService.GetMenu(input);
        }

        /// <summary>
        /// 获取系统菜单树，用于新增、编辑时选择上级节点
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("tree")]
        public async Task<dynamic> GetMenuTree([FromQuery] MenuInput input)
        {
            return await _sysMenuService.GetMenuTree(input);
        }

        /// <summary>
        /// 获取系统菜单树，用于给角色授权时选择
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("treeForGrant")]
        public async Task<dynamic> TreeForGrant([FromQuery] MenuInput input)
        {
            return await _sysMenuService.TreeForGrant(input);
        }
    }
}
